package com.example.administrator.familfinalcialmanagement.ui.fragment;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.familfinalcialmanagement.R;
import com.example.administrator.familfinalcialmanagement.bean.LoginBean;
import com.example.administrator.familfinalcialmanagement.databinding.FragmentMyselfBinding;
import com.example.administrator.familfinalcialmanagement.ui.activity.AboutMeActivity;
import com.example.administrator.familfinalcialmanagement.ui.activity.LoginOutActivity;
import com.example.administrator.familfinalcialmanagement.ui.activity.MyMoneyActivity;
import com.example.administrator.familfinalcialmanagement.ui.activity.MyOrdersActivity;
import com.example.administrator.familfinalcialmanagement.ui.activity.ToastActivity;
import com.example.administrator.familfinalcialmanagement.util.ApiHTTP;
import com.example.administrator.familfinalcialmanagement.util.SpUtils;
import com.example.administrator.familfinalcialmanagement.util.ToastUtil;
import com.lzy.okgo.callback.StringCallback;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by Administrator on 2019/3/26.
 */

public class MySelfFragment extends BaseLazyFragment {

    FragmentMyselfBinding binding;

    LoginBean bean = (LoginBean) SpUtils.getBean("module_loginBean");

    /**
     * 1 未发货
     * 2 已发货
     * 3 已完成
     * 4 已支付
     */
    String type = "1";

    @Override
    protected View inflaterView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(getActivity()), R.layout.fragment_myself, container, false);
        binding.setFragment(this);
        return binding.getRoot();
    }

    //懒加载，在界面消失的时候调用的方法，终结当前界面的操作
    @Override
    protected void onVisible() {

    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated( view, savedInstanceState );



    }

    //懒加载，只有在界面显示的时候才会调用的方法，用来节约手机资源消耗
    @Override
    protected void lazyLoad() {

        if (bean != null) {
            binding.tvModuleName.setText(bean.getData().getAccount());
            binding.tvModulePhone.setText(bean.getData().getTel());
            binding.tvModuleEmail.setText(bean.getData().getEmail());
        }

        binding.linMyMonery.setOnClickListener(this);
        binding.llModuleMyCommission.setOnClickListener(this);
        binding.llModuleAboutOur.setOnClickListener(this);
        binding.llModuleSet.setOnClickListener(this);
        binding.llModuleName.setOnClickListener(this);
        binding.tvModuleOne.setOnClickListener( this );
        binding.tvModuleTwo.setOnClickListener( this );
        binding.tvModuleThree.setOnClickListener( this );
        binding.tvModuleFour.setOnClickListener( this );
    }

    @Override
    public int setLayoutId() {
        return R.layout.fragment_index;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tvModuleOne:
                type = "1";
                startActivity(new Intent(getActivity(), MyOrdersActivity.class)
                        .putExtra( "module_type",type ));
                break;
            case R.id.tvModuleTwo:
                type = "2";
                startActivity(new Intent(getActivity(), MyOrdersActivity.class)
                        .putExtra( "module_type",type ));
                break;
            case R.id.tvModuleThree:
                type = "3";
                startActivity(new Intent(getActivity(), MyOrdersActivity.class)
                        .putExtra( "module_type",type ));
                break;
            case R.id.tvModuleFour:
                type = "4";
                startActivity(new Intent(getActivity(), MyOrdersActivity.class)
                        .putExtra( "module_type",type ));
                break;
            case R.id.lin_myMonery:
                startActivity(new Intent(getActivity(), MyOrdersActivity.class)
                .putExtra( "module_type",type ));
                break;
            case R.id.llModuleAboutOur:
                ToastUtil.showToast("关于我们");
                startActivity(new Intent(getActivity(),AboutMeActivity.class));
                break;
            case R.id.llModuleSet:
                startActivity(new Intent(getActivity(), LoginOutActivity.class));
                break;
            default:
        }
    }



}